package everyday.m20230309;

import java.util.Locale;

/**
 * leetcode题831
 */
public class Q20230401 {

    enum Type {
        EMAIL, PHONE_NUMBER
    }

    private Type checkType(String s) {
        if (s.contains("@")) {
            return Type.EMAIL;
        }
        return Type.PHONE_NUMBER;
    }

    public String maskPII(String s) {
        Type type = checkType(s);
        switch (type) {
            case EMAIL -> {
                String s1 = s.toLowerCase(Locale.ROOT);
                String[] split = s1.split("@");
                String name = split[0].charAt(0) + "*****" + split[0].charAt(split[0].length() - 1);
                return name + "@" + split[1];
            }
            case PHONE_NUMBER -> {
                String s1 = s.replaceAll("[ ()+-]", "");
                int length = s1.length();
                int countryNumLen = length - 10;
                String countryPrefix = "";
                if (countryNumLen == 1) {
                    countryPrefix = "+*-";
                } else if (countryNumLen == 2) {
                    countryPrefix = "+**-";
                } else if (countryNumLen == 3) {
                    countryPrefix = "+***-";
                }
                return countryPrefix + "***-***-"+s1.substring(length - 4);
            }
            default -> {
                return s;
            }
        }
    }

    public static void main(String[] args) {
        Q20230401 x = new Q20230401();
        System.out.println(x.checkType("xWveUQxEtPpeaBHAnoNICYShD@QctQvemY.GpUkh"));
    }
}
